package com.hu.controller;

import com.hu.bookstorecommon.entity.DataPage;
import com.hu.bookstorecommon.entity.book;
import com.hu.bookstorecommon.entity.category;
import com.hu.service.bookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class bookController {

    @Autowired
    private bookService bookService;

    @RequestMapping("/allBook")
    public  String getAllBook(Integer pageNum, Integer cid, String bookName, String authorName, Model model){

        Integer pid = pageNum==null? 1 : pageNum;
      String bname=bookName==null?"":bookName;
      String aname=authorName==null?"":authorName;
      Integer cid1=cid==null?0:cid;
        //System.out.println(pid+bname+aname+cid1);
         DataPage<book> book= bookService.getAllBooks(pid,cid1,aname,bname);



        List<category> categoryList=bookService.getAllCateGory();
        //System.out.println(categoryList);
        model.addAttribute("bookName",bname);
        model.addAttribute("authorName",aname);
       model.addAttribute("book",book);
       model.addAttribute("cid",cid1);
       model.addAttribute("cateGory",categoryList);
       return "book-list";
    }
}
